package entity;

import java.util.HashMap;

public class ParameterMap {
	
	public static final int STRING = 0;
	public static final int INTEGER = 1;
	public static final int ENTITY = 2;
	
	private final HashMap<String, Object> parameterMap = new HashMap<String, Object>();
	private final HashMap<String, Integer> typeMap = new HashMap<String, Integer>();
	
	public void setString(String name, String value){
		parameterMap.put(name, value);
		typeMap.put(name, STRING);
	}
	
	public void setInteger(String name, Integer value){
		parameterMap.put(name, value);
		typeMap.put(name, INTEGER);
	}
	
	public void setEntity(String name, Entity value){
		parameterMap.put(name, value);
		parameterMap.put(name, ENTITY);
	}
	
	public String getString(String name){
		String result = (String) parameterMap.get(name);
		return result;
	}
	
	public Integer getInteger(String name){
		Integer result = (Integer) parameterMap.get(name);
		return result;
	}
	
	public Entity getEntity(String name){
		Entity result = (Entity) parameterMap.get(name);
		return result;
	}
	
	public int getType(String name){
		int result = typeMap.get(name);
		return result;
	}
	
	public String[] getParameterNameList(){
		String[] result = parameterMap.keySet().toArray(new String[0]);
		return result;
	}
	
	@Override
	public ParameterMap clone(){
		ParameterMap result = new ParameterMap();
		String [] nameList = getParameterNameList();
		for(int i=0; i<nameList.length; i++){
			String name = nameList[i];
			int type = typeMap.get(name);
			if(type == STRING){
				result.setString(name, (String) parameterMap.get(name));
			}else if(type == INTEGER){
				result.setInteger(name, (Integer) parameterMap.get(name));
			}else if(type == ENTITY){
				result.setEntity(name, (Entity) parameterMap.get(name));
			}
		}
		return result;
	}

}
